package org.myproject.service;

import java.util.List;

import org.myproject.domain.Click;
import org.myproject.persistence.Dao;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author Ryan Gravener 
 *
 */

public class ClickService {

	private Dao dao;

	public void setDao(Dao dao) {
		this.dao = dao;
	}
	
	@Transactional
	public Click saveClick(Click click) {
		/**
		 * blazeds converts NaN to 0, set it to null
		 */
		if(click.getId()==0) {
			click.setId(null);
		}
		dao.saveOrUpdate(click);
		return click;
	}
	
	@SuppressWarnings("unchecked")
	@Transactional
	public List<Click> getClicks() {
		return dao.createQuery("from Click order by created desc").setMaxResults(125).list();
	}
}
